import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

//自定义组件
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // MaterialApp是根组件
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('ListView.builder'),
        ),
        body: HomeContent(),
      ),
      theme: ThemeData(primaryColor: Colors.blue),
    );
  }
}

//body内容组件
class HomeContent extends StatelessWidget {
  List list = [];
  HomeContent() {
    //真实场景是从服务器获取数据然后生成list widget
    for (var i = 0; i < 3; i++) {
      list.add(ListTile(
        title: Text("我是$i"),
      ));
    }
  }
  @override
  Widget build(BuildContext context) {
    return ListView.builder(
        itemCount: this.list.length,
        itemBuilder: (context, index) {
          //返回一个widget
          return this.list[index];
        });
  }
}
